﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AlarmClock
{
    public partial class LxzhTextBox : TextBox
    {
        private int index=-1;
        private String label;
        private DateTime cdDate;
        private bool isFinished = false;

        [Browsable(false)]
        public int Index
        {
            set
            {
                index = value;
            }
            get
            {
                return index;
            }
        }
        [Browsable(false)]
        public DateTime Date
        {
            get { return cdDate; }
            set
            {
                cdDate = value;
            }
        }
        public string Label{
            get { return label; }
            set
            {
                label = value;
            }
        }
        [Browsable(false)]
        public bool IsFinished
        {
            get { return isFinished; }
            set { isFinished = value; }
        }

        public LxzhTextBox()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            DateTime nowTime = DateTime.Now;
            if (cdDate > nowTime)
            {
                String deltaTime = CalculatorStr.CalculateDeltaTime(nowTime,cdDate);
                this.Text = label + ":" + deltaTime;
                isFinished = false;
                if ((cdDate - nowTime).TotalSeconds < 1)
                {
                    this.Text = label + ":已结束";
                    isFinished = true;
                    TimeUp.Ring(RingType.RING_SHORT);
                    timer1.Stop();
                    timer1.Enabled = false;
                }
            }
            else
            {
                this.Text = label + ":已结束";
                isFinished = true;
                timer1.Stop();
                timer1.Enabled = false;
            }
        }

        public void start(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1_Tick(sender, e);
        }
    } 
}
